import { _decorator, Collider2D, Component, Contact2DType, IPhysics2DContact, Node, physics } from "cc";
import { nsColliedUtil } from "../../Extend/ColliedUtil";
const { ccclass, property } = _decorator;

@ccclass("OneSidePlatform")
export class OneSidePlatform extends Component {
    start() {
        let collider = this.getComponent(Collider2D);
        if (collider) {
            collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
        }
    }

    onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        // 只在两个碰撞体开始接触时被调用一次
        if (nsColliedUtil.isHero(otherCollider)) {
            if (contact) {
                let normal = contact.getManifold().localNormal;
                if (normal.x != 0 || normal.y != 1) {
                    contact.disabled = true;
                }
            }
        }
    }
}
